<?php
declare (strict_types=1);

namespace magein\sms\service\laravel;

use magein\sms\Sms;
use Illuminate\Support\ServiceProvider;

class SmsServiceProvider extends ServiceProvider
{
    /**
     * 注册服务
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('sms', function ($app) {
            $sms = new Sms();
            $sms->setConfig(config('sms') ?: []);
            return $sms;
        });
    }

    /**
     * 执行服务
     *
     * @return void
     */
    public function boot()
    {
        // 加载函数
        $this->loadFunc();

        // 注册路由
        $this->loadRoutesFrom(__DIR__ . '/route.php');
    }

    protected function loadFunc()
    {
        include __DIR__ . '/common.php';
    }
}
